<?php
require_once "config.php";
$offer_obj = new Offer();
$active_offers = $offer_obj->list_active_offers();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Hotels With Offers</title>
<script language="Javascript" type="text/javascript" src="js/jquery.min.js"></script>
<script language="Javascript" type="text/javascript" src="js/jquery.countdown.js"></script>
<script language="Javascript" type="text/javascript" src="js/misc.js"></script>
<link href="css/main.css" rel="stylesheet" type="text/css" />

     <script language="javascript" type="text/javascript">
         $(function(){
          <?php $k = 1;
        foreach ($active_offers as $active_offer) {
                                    $offer_hour = substr($active_offer['offer_end_date'], 11, 2) ;
               $offer_min =  substr($active_offer['offer_end_date'], 14, 2);
               $offer_sec =  substr($active_offer['offer_end_date'], 17, 2);
               $offer_day =  substr($active_offer['offer_end_date'], 8, 2);
               $offer_month =  substr($active_offer['offer_end_date'], 5, 2);
               $offer_year =  substr($active_offer['offer_end_date'], 0, 4);
               $date = array();
	$date['secs'] = 20;
	$date['mins'] = 12;
	$date['hours'] = 12;
	$date['days'] = 23;
       $target = mktime(
		$offer_hour,
		$offer_min,
		$offer_sec,
		$offer_month,
		$offer_day,
		$offer_year
	);
            $diffSecs = $target - time();
             /*echo date('Y-m-d H:i:s',$diffSecs);*/

               ?>
                   console.log("<?php echo date("Y-m-d H:i:s",$diffSecs);?>");
        $('#counter_<?=$k?>').countdown({
          image: 'images/digits.png',
          startTime: '<?=$date['days']?>:<?=$date['hours']?>:<?=$date['mins']?>:<?=$date['secs']?>',
          timerEnd: function(){ alert('end!'); }
        });
<?php
    $k++;
        }
        ?>

      });



		</script>
  <style type="text/css">
      br { clear: both; }
      .cntSeparator {
        font-size: 54px;
        margin: 10px 7px;
        color: #000;
      }
      .desc { margin: 7px 3px; }
      .desc div {
        float: left;
        font-family: Arial;
        width: 70px;
        margin-right: 65px;
        font-size: 13px;
        font-weight: bold;
        color: #000;
      }
    </style>
</head>

<body>
<div id="wrapper">

    
<div class="contentPane">

  <div class="leftPane">

    <div id="Listings">
        <?php
        if(!empty($active_offers)) {
        
           
            $j =1;
            foreach ($active_offers as $active_offer) {
               $you_saved = $active_offer['regular_amount'] - $active_offer['discount_amount'];
               $discount_percentage = ceil((($active_offer['regular_amount'] - $active_offer['discount_amount'])/$active_offer['regular_amount'])*100);
               $item_sold = $offer_obj->get_noof_sold_items($active_offer['offer_id']);
             
              
               

?>
       
      
    
      <div class="item">
        
          <div class="countdown">Offer ends in<br />
                <div id="counter_<?=$j?>"></div>
           </div>
          <br/>
        
      <?php
      $j++;
            }

        }
        ?>

     
    </div>
    <div class="clear"></div>
</div>
</div>
<div class="clear"></div>
</div>

</body>
</html>
